package com.example.designpatterns.behavioral.interpreter;

import java.util.HashMap;
import java.util.Map;

/**
 * 上下文角色
 *
 * @author scott
 */
public class Context {

    private String text;
    private Map<String, String> rules;

    public Context(String text) {
        this.text = text;
        this.rules = new HashMap<>();
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public void addRule(String word, String replacement) {
        rules.put(word, replacement);
    }

    public String getReplacement(String word) {
        return rules.getOrDefault(word, "");
    }

}
